package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.mapper.BlackListMapper;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {
    @Autowired
    private BlackListMapper blackListMapper;
    @Override
    public PageBeanVo findByPage(Long userId, Integer pageNum, Integer pageSize) {
        //开启分页
        Page<BlackList> page = new Page<>(pageNum, pageSize);
        //书写动态spl条件
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        //调用分页查询方法，获得分页对象
        page = blackListMapper.selectPage(page, qw);
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }

    @Override
    public void delete(Integer uid, Long id) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id",id);
        qw.eq("black_user_id",uid);
        blackListMapper.delete(qw);

    }
}
